package com.ketti.team;

import android.app.TabActivity;
import android.os.Build;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.TabHost;
import android.widget.TextView;

/**
 * @author JaeGwang Ryu
 * @since 		@version
 * 2010,04,23 	0.10	Create tab that height is height of text.
 * 2010,04,23	0.11	Apply background image for tab.
 * 
 * */
public class EditorActivity extends TabActivity {
	
	private TabHost mTabHost = null;
		
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
              
        mTabHost = getTabHost();
        
        LayoutInflater.from(this).inflate(R.layout.main,
        		mTabHost.getTabContentView(), true);
        
        
         /** When Program started, showed '+' tab only. */
        createTab("+");
    }

    /**
     * create new tab (Tab label is filename.)
     * @param filename : if selected 'New' menu, put value, "*.extension"
     * 					 if selected 'Open' menu, put filename.
     * */
	public void createTab(String filename)
    {	
		// put only label view instead of TabWidget with label&icon
    	mTabHost.addTab(
    			mTabHost.newTabSpec("tab")
    			.setIndicator(createIndicatorViewOnlyLabel(filename))
    			.setContent(R.id.tabhost));
    }
	
	/** 
	 * create tab widget only label without icon.
	 * @param label : if selected 'New' menu, put value, "*.extension"
     * 				  if selected 'Open' menu, put filename.
	 * @return : tab widget only label
	 */
	public View createIndicatorViewOnlyLabel(String label) 
	{
		// create TextView for label
		TextView tv = new TextView(this);
		tv.setLayoutParams(new LayoutParams(				// set layout
				LayoutParams.WRAP_CONTENT, 
				LayoutParams.WRAP_CONTENT));
		tv.setGravity(Gravity.CENTER);						// set on center
		tv.setText(label);									// set text of label
		tv.setBackgroundResource(R.drawable.tab_indicator);	// set tab image
    
        // If Android version 1.6 of your device, show other tab image.
        if (this.getApplicationInfo().targetSdkVersion <= Build.VERSION_CODES.DONUT)
        {
            // Donut apps get old color scheme
            tv.setBackgroundResource(R.drawable.tab_indicator_v4);
            tv.setTextColor(this.getResources().getColorStateList(R.color.tab_indicator_text_v4));
        }
        return tv;
    }
}